package com.gcsoftware.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by qs on 2018/3/19.
 */
public class MapUtils extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public MapUtils() {
        this.put((String)"code", Integer.valueOf(0));
        this.put((String)"msg", "success");
    }

    public static MapUtils error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static MapUtils error(String msg) {
        return error(500, msg);
    }

    public static MapUtils error(int code, String msg) {
        MapUtils r = new MapUtils();
        r.put((String)"code", Integer.valueOf(code));
        r.put((String)"msg", msg);
        return r;
    }

    public static MapUtils ok(String msg) {
        MapUtils r = new MapUtils();
        r.put((String)"msg", msg);
        return r;
    }

    public static MapUtils ok(Map<String, Object> map) {
        MapUtils r = new MapUtils();
        r.putAll(map);
        return r;
    }

    public static MapUtils ok() {
        return new MapUtils();
    }

    public MapUtils put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
